@echo off
echo 正在部署计件工资管理系统...

REM 设置Qt路径（根据实际安装路径修改）
REM 假设Qt安装在默认路径下，如果不同请修改
set QT_PATH=C:\Qt\5.15.2\mingw81_64
set PATH=%QT_PATH%\bin;%PATH%

REM 检查windeployqt是否存在
where windeployqt >nul 2>&1
if %errorlevel% neq 0 (
    echo 错误：找不到windeployqt工具，请检查Qt安装路径
    echo 当前QT_PATH设置为: %QT_PATH%
    echo.
    echo 请检查：
    echo 1. Qt是否已安装在 %QT_PATH%
    echo 2. Qt版本是否为5.15.2 MinGW 64-bit
    echo 3. 是否需要修改此脚本中的QT_PATH变量
    pause
    exit /b 1
)

REM 创建部署目录
if exist "deployment" rmdir /s /q "deployment"
mkdir "deployment"

REM 复制可执行文件
if exist "build\release\oa.exe" (
    copy "build\release\oa.exe" "deployment\"
) else if exist "build\debug\oa.exe" (
    copy "build\debug\oa.exe" "deployment\"
) else if exist "build\oa.exe" (
    copy "build\oa.exe" "deployment\"
) else (
    echo 错误：找不到可执行文件，请先构建项目
    pause
    exit /b 1
)

REM 使用windeployqt部署Qt运行时库
echo 正在部署Qt运行时库...
windeployqt --dir "deployment" --plugindir "deployment/plugins" --qmldir "." "deployment\oa.exe"

REM 复制数据库文件（如果存在）
if exist "toy_factory.db" (
    copy "toy_factory.db" "deployment\"
)

REM 复制平台插件
if exist "%QT_PATH%\plugins\platforms" (
    xcopy "%QT_PATH%\plugins\platforms" "deployment\plugins\platforms\" /E /I /Y
)

REM 复制其他必要插件
if exist "%QT_PATH%\plugins\imageformats" (
    xcopy "%QT_PATH%\plugins\imageformats" "deployment\plugins\imageformats\" /E /I /Y
)

if exist "%QT_PATH%\plugins\styles" (
    xcopy "%QT_PATH%\plugins\styles" "deployment\plugins\styles\" /E /I /Y
)

echo.
echo 部署完成！独立应用程序位于 deployment 目录中。
echo 您可以将整个 deployment 目录打包分发给其他用户。
echo.

pause